package com.zlx.guguanjia.mapper;


import com.zlx.guguanjia.entity.SysArea;
import com.zlx.guguanjia.mapper.provider.SysAreaSqlProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
public interface SysAreaMapper extends Mapper<SysArea> {
    
    /***
     * @Author 周罗校
     * @Description 
     * @Param [map] {sid:区域id，name：模糊查询区域名}
     * @return java.util.List<com.zlx.guguanjia.entity.SysArea>
     * @Date 2020.10.30 13:34:44
     **/
    @SelectProvider( type= SysAreaSqlProvider.class,method = "selectPage")
    List<SysArea> selectPage(Map<String,Object> map);

    @Select("SELECT " +
            " sa.*, " +
            " parent.`name` parent_name  " +
            "FROM " +
            " `sys_area` sa " +
            " LEFT JOIN sys_area parent ON sa.parent_id = parent.id  " +
            "WHERE " +
            " sa.id = #{id}")
    SysArea selectById(Long id);

    @Update("UPDATE sys_area  " +
            "SET  " +
            "parent_ids = REPLACE ( parent_ids, #{oldParentIds}, #{parentIds} )  " +
            "WHERE " +
            "FIND_IN_SET(#{parentId},parent_ids)")
    int updateByParentIds(@Param("oldParentIds") String oldParentIds,@Param("parentIds") String parentIds,@Param("parentId") Long parentId);


    @SelectProvider( type= SysAreaSqlProvider.class,method = "insertBitch")
    void insertBitch(@Param("areas") List<SysArea> areas);
}